package cn.wolfcode.trip.base.service.impl;

import cn.wolfcode.trip.base.domain.TravelComment;
import cn.wolfcode.trip.base.mapper.TravelCommendMapper;
import cn.wolfcode.trip.base.mapper.TravelCommentMapper;
import cn.wolfcode.trip.base.query.QueryObject;
import cn.wolfcode.trip.base.service.ITravelCommentService;
import cn.wolfcode.trip.base.util.JsonResult;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class TravelCommentServiceImpl implements ITravelCommentService {
    @Autowired
    private TravelCommentMapper travelCommentMapper;
    @Override
    public PageInfo query(QueryObject qo) {
        PageHelper.startPage(qo.getCurrentPage(),qo.getPageSize(),qo.getOrderBy());
        List<TravelComment> travelComments = travelCommentMapper.queryForList(qo);
        return new PageInfo(travelComments);
    }

    @Override
    public Integer queryForCount(Long userId) {
        return travelCommentMapper.queryForCount(userId);
    }

    @Override
    public void updateState(Long userId) {
        travelCommentMapper.updateState(userId);
    }

    public List<TravelComment> getCommentByTravelId(Long travelId) {
        return travelCommentMapper.selectCommentByTravelId(travelId);
    }

    public void saveTravelComment(TravelComment travelComment) {
        travelComment.setCreateTime(new Date());
        travelCommentMapper.insert(travelComment);
    }

    public List<TravelComment> getTravelCommentsByUserId(Long userId) {
        return travelCommentMapper.getTravelCommentsByUserId(userId);
    }
}
